const { envList } = require('./envList')
App({
  globalData: {
    openId: '',
    CycleId: 0,
    GzrMoney: 0,
    JjrMoney: 0,
    XxrMoney: 0,
    IsLoad: false,
    IsUpdate: false
  },
  onLaunch: function () {
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      wx.cloud.init({
        traceUser: true,
      })
    }
    wx.cloud.callFunction({
      name: 'getOpenId',
      config: {
        env: envList[0].envId
      },
      data: {}
    }).then(res => {
      this.globalData.openId = res.result.userInfo.openId;
      wx.cloud.database({
        env: envList[1].envId
      }).collection('UserConfig').where({
        _openid: this.globalData.openId
      }).get().then(config => {
        if(config.data.length > 0) {
          this.globalData.CycleId = config.data[0].CycleId;
          this.globalData.GzrMoney = config.data[0].GzrMoney;
          this.globalData.JjrMoney = config.data[0].JjrMoney;
          this.globalData.XxrMoney = config.data[0].XxrMoney;
        }
        this.globalData.IsLoad = true;
      })
    })
  }
})
